package org.coldlife.sim.grav.settings;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class SettingsManager 
{
	private Properties applicationProps;
	private Properties defaultProps;
	
	private static final String PROPERTIES_FILE = "gravsim.properties";
	private static final String DEFAULTS_FILE = "default.properties";
	
	public final static String WINDOW_WIDTH  = "win.width";
	public final static String WINDOW_HEIGHT = "win.height";
	public final static String NUM_PARTICLE  = "particle.num";
	
	public SettingsManager()
	{
		setDefaultProps(new Properties());
		loadDefaults();
	}

	public void loadSettings() throws IOException 
	{
		setApplicationProps(new Properties(getDefaultProps()));
		InputStream in = ClassLoader.getSystemResourceAsStream(PROPERTIES_FILE);
		getApplicationProps().load(in);
		in.close();
	}

	public void loadDefaults()
	{
		InputStream in = ClassLoader.getSystemResourceAsStream(DEFAULTS_FILE);
		try {
			getDefaultProps().load(in);
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public int getInt(String key)
	{
		return Integer.valueOf(getApplicationProps().getProperty(key));
	}
	
	
	// setter / getter
	
	String getProp()
	{
		return getProp("");
	}
	
	public String getProp(String key)
	{
		return getApplicationProps().getProperty(key);
	}

	private void setDefaultProps(Properties defaultProps) {
		this.defaultProps = defaultProps;
	}

	Properties getDefaultProps() {
		return defaultProps;
	}

	private void setApplicationProps(Properties applicationProps) {
		this.applicationProps = applicationProps;
	}

	Properties getApplicationProps() {
		return applicationProps;
	}
}
